package impl.parser;

import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxEditorParser;
import org.protege.editor.owl.model.classexpression.OWLExpressionParserException;
import org.protege.editor.owl.model.parser.ParserUtil;
import org.protege.editor.owl.ui.clsdescriptioneditor.OWLExpressionChecker;
import org.semanticweb.owlapi.expression.OWLEntityChecker;
import org.semanticweb.owlapi.expression.ParserException;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;

/**
 * Author: Manuel Fink
 */
public class OWLClassExpressionCheckerCustom implements OWLExpressionChecker<OWLClassExpression> {

	private OWLEntityChecker	entityChecker;
	private OWLDataFactory		dataFactory;

	public OWLClassExpressionCheckerCustom(OWLEntityChecker entityChecker, OWLDataFactory dataFactory) {
		this.entityChecker = entityChecker;
		this.dataFactory = dataFactory;
	}

	@Override
	public void check(String text) throws OWLExpressionParserException {
		createObject(text);
	}

	@Override
	public OWLClassExpression createObject(String text) throws OWLExpressionParserException {
		try {
			ManchesterOWLSyntaxEditorParser parser = new ManchesterOWLSyntaxEditorParser(this.dataFactory, text);
			parser.setOWLEntityChecker(this.entityChecker);
			return parser.parseClassExpression();
		} catch (ParserException e) {
			throw ParserUtil.convertException(e);
		}
	}
}
